package com.fg.cloud.agency.controller.account;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fg.cloud.agency.controller.BaseAgencyController;
import com.fg.cloud.common.StatusCode;
import com.fg.cloud.common.finals.UserType;
import com.fg.cloud.common.quantity.ResultType;
import com.fg.cloud.manager.entry.agency.AgencyAccountEntity;
import com.fg.cloud.manager.service.agency.AgencyAccountService;


/**
  * Description:经销商端 账户Controller
  * @author shaoqiping
  * @date 2017年8月31日下午3:17:27
*/
@Controller
@RequestMapping("/agencyFacBill")
public class AgencyFacAccountController extends BaseAgencyController {
	
	@Autowired
	private AgencyAccountService agencyAccountService;
	/**
	  * Description:查询账户详情
	  * @param request
	  * @param response
	  * @param id
	  * @author shaoqiping
	  * @date 2017年8月31日上午9:20:39
	*/
	@RequiresRoles(UserType.AGENCY)
	@RequestMapping(value = "/find", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public void find(HttpServletRequest request, HttpServletResponse response){
		try {
			AgencyAccountEntity agencyAccount =new AgencyAccountEntity();
			agencyAccount.setAgeId(getCurrentAgencyUser().getAgeId());
			agencyAccount.setFacId(getCurrentAgencyUser().getFacId());
			List<AgencyAccountEntity> account=agencyAccountService.findAccount(agencyAccount);
			if(account.size()>0){
				doResult(response, true, StatusCode.FINDSUCCESS, account, ResultType.FIND_SUCCESS);
			}else{
				doResult(response, false, StatusCode.FINDERROR, account, ResultType.FIND_FAULT);
			}
		} catch (Exception e) {
			e.printStackTrace();
			doResult(response, false, StatusCode.EXCEPTIONERROR, null, e.getMessage());
		}
	}
}
